package com.son.hotel.controller;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.son.hotel.common.ErrorCode;
import com.son.hotel.common.Result;
import com.son.hotel.domain.RoomType;
import com.son.hotel.execption.BusinessException;
import com.son.hotel.service.RoomTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@Tag(name = "房间类型信息")
@CrossOrigin(origins = {"http://localhost:8081"},allowCredentials = "true")
@RequestMapping("/menu")
public class RoomTypeController {

    @Autowired
    private RoomTypeService roomTypeService;

    /**
     *查询所有房间的型号
     * @return
     */
    @Operation(summary = "查询所有房间信息")
    @GetMapping("/list")
    public Result<List<RoomType>> listAllRoomType(){
        List<RoomType> list = roomTypeService.list();
        if (CollectionUtil.isEmpty(list)){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"列表为空");
        }
        return Result.success("200",list);
    }
}
